<template>
	<!-- 
		使用方法
			<uni-nav-bar
				left-image="back"
				title="发任务"
				color="#000"
				fixed="true"
				status-bar="true"
				shadow="true"
				rightText="发布"
				@clickRight="menu()"
			>
			</uni-nav-bar> 
	-->
	<view class="uni-navbar">
		<view :class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }" :style="{ 'background': backgroundColor }"
		 class="uni-navbar__content">
			<uni-status-bar v-if="statusBar"  :backgroundColor="backgroundColor" :color="color"/>
			<view :style="{ color: color,backgroundColor: backgroundColor }" class="uni-navbar__header uni-navbar__content_view">
				<view @tap="onClickLeft" class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
					<!-- <view class="uni-navbar__content_view" v-if="leftIcon.length">
						<uni-icons :color="color" :type="leftIcon" size="24" />
					</view> -->
					<!-- <view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view"
					 v-if="leftText.length">
					 {{leftImage}}
						
					</view> -->
					<text :style="{ color: color, fontSize: '14px' }">{{ leftText }}</text>
					<image
						class="uni-navbar__content_image" 
						:class="leftImage == 'back'? 'uni-navbar__content_image_back':''" 
						:src="leftImage == 'back' ? '/static/index/back.png':leftImage" mode=""
						:style="{op: color}"
						>
					</image>
					<slot name="left" />
				</view>
				<view class="uni-navbar__header-container uni-navbar__content_view">
					<view class="uni-navbar__header-container-inner uni-navbar__content_view" v-if="title.length">
						<text class="uni-nav-bar-text" :style="{color: color }">{{ title }}</text>
					</view>
					<!-- 标题插槽 -->
					<slot />
				</view>
				<view :class="title.length ? 'uni-navbar__header-btns-right' : ''" @tap="onClickRight" class="uni-navbar__header-btns uni-navbar__content_view">
					<!-- <view class="uni-navbar__content_view" v-if="rightIcon.length">
						<uni-icons :color="color" :type="rightIcon" size="24" />
					</view> -->
					<!-- 优先显示图标 -->
					<view class="uni-navbar-btn-text uni-navbar__content_view" v-if="(rightText.length && !rightIcon.length) || rightImage.length">
						<view :class="rightBottomText ? 'uni-nav-bar-right' : ''">
							<view class="uni-nav-bar-right-text">{{ rightText }}</view>
							<view class="uni-nav-bar-right-text" v-if="rightBottomText">{{ rightBottomText }}</view>
						</view>
						<image class="uni-navbar__content_image" v-if="rightImage" :src="rightImage" mode=""></image>
					</view>
					<slot name="right" />
				</view>
			</view>
		</view>
		<view class="uni-navbar__placeholder" v-if="fixed">
			<uni-status-bar v-if="statusBar" :backgroundColor="backgroundColor" :color="color"/>
			<view class="uni-navbar__placeholder-view" />
		</view>
	</view>
</template>

<script>
	import uniStatusBar from "../uni-status-bar/uni-status-bar.vue";
	import uniIcons from "../uni-icons/uni-icons.vue";

	export default {
		name: "UniNavBar",
		components: {
			uniStatusBar,
			uniIcons
		},
		props: {
			title: {
				type: String,
				default: ""
			},
			leftText: {
				type: String,
				default: ""
			},
			rightText: {
				type: String,
				default: ""
			},
			rightBottomText:{
				type: String,
				default: ""
			},
			leftIcon: {
				type: String,
				default: ""
			},
			leftImage: {
				type: String,
				default: ""
			},
			rightIcon: {
				type: String,
				default: ""
			},
			rightImage: {
				type: String,
				default: ""
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: "#000000"
			},
			backgroundColor: {
				type: String,
				default: "#FFFFFF"
			},
			statusBar: {
				type: [Boolean, String],
				default: false
			},
			shadow: {
				type: [String, Boolean],
				default: false
			},
			border: {
				type: [String, Boolean],
				default: true
			}
		},
        mounted() {
          if(uni.report && this.title !== '') {
              uni.report('title', this.title)
          }
        },
		methods: {
			onClickLeft() {
				if(this.leftImage == "back"){
					// #ifdef H5
					history.back()
					// #endif
					//#ifndef H5
					uni.navigateBack()
					// #endif
				}
				this.$emit("clickLeft");
			},
			onClickRight() {
				this.$emit("clickRight");
			}
		}
	};
</script>

<style lang="scss" scoped>
	$nav-height: 44px;
	.uni-nav-bar-text {
		max-width: 450rpx;
		/* #ifdef APP-PLUS */
		font-size: 36rpx;
		/* #endif */
		/* #ifndef APP-PLUS */
		// font-size: $uni-font-size-lg;
		font-size: 36rpx;
		/* #endif */
		font-weight: 500;
		text-align: center;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.uni-nav-bar-right-text {
		font-size: $uni-font-size-base;
	}

	.uni-navbar {
		width: 750rpx;
	}

	.uni-navbar__content {
		position: relative;
		width: 750rpx;
		background-color: $uni-bg-color;
		overflow: hidden;
	}

	.uni-navbar__content_view {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		align-items: center;
		flex-direction: row;
		// background-color: #FFFFFF;
	}

	.uni-navbar__header {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		width: 750rpx;
		height: $nav-height;
		line-height: $nav-height;
		font-size: 16px;
		// background-color: #ffffff;
	}

	.uni-navbar__header-btns {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-wrap: nowrap;
		width: 120rpx;
		padding: 0 6px;
		justify-content: center;
		align-items: center;
	}

	.uni-navbar__header-btns-left {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 150rpx;
		justify-content: flex-start;
	}

	.uni-navbar__header-btns-right {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 150rpx;
		padding-right: 30rpx;
		justify-content: flex-end;
	}

	.uni-navbar__header-container {
		flex: 1;
	}

	.uni-navbar__header-container-inner {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		align-items: center;
		justify-content: center;
		font-size: $uni-font-size-base;
	}


	.uni-navbar__placeholder-view {
		height: $nav-height;
	}

	.uni-navbar--fixed {
		position: fixed;
		z-index: 998;
	}

	.uni-navbar--shadow {
		/* #ifndef APP-NVUE */
		// box-shadow: 0 1px 6px #ccc;
		border-bottom: 1rpx solid #e5e5e5;
		/* #endif */
	}
	// 底线
	.uni-navbar--border {
		// border-bottom-width: 1rpx;
		// border-bottom-style: solid;
		// border-bottom-color: $uni-border-color;
	}
	.uni-navbar__content_image{
		width: 36rpx;
		height: 36rpx;
		margin-left: 10rpx;
	}
	.uni-navbar__content_image_back{
		width: 30rpx !important;
		height: 36rpx !important;
	}
	.uni-nav-bar-right{
		line-height: 30rpx;
	}
</style>
